package com.mcy.test01.dao;

import com.mcy.test01.pojo.Deparment;
import com.mcy.test01.pojo.Employee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import java.util.Collection;
import java.util.Map;

//员工dao
public class EmployeeDao {
    //模拟数据查询
    private static Map<Integer, Employee> Employees=null;
    private DepartmentDao departmentDao=new DepartmentDao();
    static {
        Employees.put(101,new Employee(101,"小明","mcyelm@163.com",1,new Deparment(101,"教学部")));
        Employees.put(101,new Employee(102,"小红","mcyelm@163.com",0,new Deparment(102,"市场部")));
        Employees.put(101,new Employee(103,"小白","mcyelm@163.com",1,new Deparment(103,"教研部")));
    }
    private static Integer initId=104;
    public Employee save(Employee employee){
        if(employee.getId()==null){
            employee.setId(initId++);
        }
        employee.setDeparment(departmentDao.getDepartmentById(employee.getDeparment().getId()));
        Employees.put(employee.getId(),employee);
        return employee;
    }
    //查询全部员工
    public Collection getAllEmployee(){
        return  Employees.values();
    }
    //通过id查询员工
    public Employee getEmployById(Integer id){
        return Employees.get(id);
    }
    //删除员工
    public void delete(Integer id){
        Employees.remove(id);
    }
}
